#include "TrajLoopSimul.h"

#include "Parameters.h"
#include "TrajSimul.h"

#include <sstream>
#include <iostream>
#include <QString>

using namespace std;

TrajLoopSimul::TrajLoopSimul()
{

}

TrajLoopSimul::~TrajLoopSimul()
{

}

MultiLayer TrajLoopSimul::solve(Clock clock,Output output,Pulse *field,Pulse *current,MultiLayer multiLayer)
{
  Parameters *p=Parameters::getInstance();
  int loopcounter=0;
  QString oldfile=output.getFileName();
  for(field->setLevel(p->getDouble("minField"));field->getLevel(clock.getTimeStamp())<=p->getDouble("maxField");field->setLevel(field->getLevel(clock.getTimeStamp())+p->getDouble("fieldStep")))
    {  
      for(current->setLevel(p->getDouble("minCurrent"));current->getLevel(clock.getTimeStamp())<=p->getDouble("maxCurrent");current->setLevel(current->getLevel(clock.getTimeStamp())+p->getDouble("currentStep")))
	{
	  ostringstream sfield,scurrent;
	  sfield<<field->getLevel(clock.getTimeStamp());
	  scurrent<<current->getLevel(clock.getTimeStamp());
	  QString newfile=oldfile;
	  newfile.append("_B_");
	  newfile.append(sfield.str());
	  newfile.append("_I_");
	  newfile.append(scurrent.str());
	  newfile.append("_.txt");
	  output.setFileName(newfile);
	  TrajSimul().solve(clock,output,field,current,multiLayer);
	  loopcounter++;
	}
    }
  return multiLayer;
}
